//
//  CAIPhotoBrowseCollectionCell.m
//  CAIImagePickerControllerKit
//
//  Created by 海参 on 2022/8/9.
//

#import "CAIPhotoBrowseCollectionCell.h"
#import <SDWebImage/SDWebImage.h>

@interface CAIPhotoBrowseCollectionCell ()

@property (nonatomic, strong) UIImageView *imageView;

@end


@implementation CAIPhotoBrowseCollectionCell

- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        [self setUI];
        [self addLayout];
    }
    return self;
}


- (void)setUI{
  
    [self.contentView addSubview:self.imageView];
    
}

- (void)addLayout{
    
}



- (void)layoutSubviews
{
    [super layoutSubviews];
    self.imageView.frame = self.bounds;
}

#pragma mark - setData

- (void)setData:(id)photo{
   
    if ([photo isKindOfClass:[NSString class]]) {
        if ([photo hasPrefix:@"http"]) {
            [self.imageView sd_setImageWithURL:[NSURL URLWithString:photo] placeholderImage:nil];
        } else {
            UIImage *image = [UIImage imageNamed:photo];
            if (!image) {
                [UIImage imageWithContentsOfFile:photo];
            }
            self.imageView.image = image;
        }
    } else if ([photo isKindOfClass:[UIImage class]]) {
        self.imageView.image = (UIImage *)photo;
    }
}


#pragma mark - 

- (UIImageView *)imageView{
    if (!_imageView) {
        UIImageView *view = [[UIImageView alloc] init];
        view.clipsToBounds = YES;
        _imageView = view;
    }
    return _imageView;
}

@end
